#! /usr/bin/python

import time
import math

tt = time.time()

up = 10**12
sup = int(math.sqrt(up))
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)

def generate(up):
   ss = 0
   for x in range(1, sup):
       for a in range(2, int(math.pow(up, float(1)/3))):
	   first = x**2 * a**3
	   if first >= up: break
	   for b in range(1, a):
	       if gcd(a, b) == 1:
		  n = first*b + b**2*x
		  if n >= up: break
		  if int(math.sqrt(n))**2 == n:
		     ss += n
		     print n, x, a, b
   return ss
    
def isProgressive(n, rn):
    start = int(math.pow(n, float(1)/3)) + 1
    for d in range(start, rn):	
	r = n%d
	if r == 0: continue
	q = n/d
	if r*q == d**2:
	   print r, d, q, rn, start
	   return True
	#print r, d, q, n 
    return False

print generate(up)

print time.time() - tt
